% Copyright (c) 1987 Free Software Foundation, Inc.

% This file is *not* part of GNU Emacs.

% This file is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY.  No author or distributor
% accepts responsibility to anyone for the consequences of using it
% or for whether it serves any particular purpose or describes
% any piece of software unless they say so in writing.  Refer to the
% GNU Emacs General Public License for full details.
%
% Permission is granted to copy, modify and redistribute this source
% file provided the copyright notice and permission notices are
% preserved on all copies.
%
% Permission is granted to process this file through TeX and print the
% results, provided the printed document carries copyright and
% permission notices identical to the ones below.

% This file is intended to be processed by plain TeX (TeX82).
%
% The final reference card has six columns, three on each side.
% This file can be used to produce it in any of three ways:
% 1 column per page
%    produces six separate pages, each of which needs to be reduced to 80%.
%    This gives the best resolution.
% 2 columns per page
%    produces three already-reduced pages.
%    You will still need to cut and paste.
% 3 columns per page
%    produces two pages which must be printed sideways to make a
%    ready-to-use 8.5 x 11 inch reference card.
%    For this you need a dvi device driver that can print sideways.
% Which mode to use is controlled by setting \columnsperpage above.
%
% Author:
%  Stephen Gildea
%  UUCP: mit-erl!gildea
%  Internet: gildea@erl.mit.edu
%
% Thanks to Paul Rubin, Bob Chassell, Len Tower, and Richard Mlynarik
% for their many good ideas.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Modifications for the Atari ST System variables
%%
%%  Frank Ridderbusch
%%  Email: ridderbusch.kd@sni.de	     (Rest of World)
%%         ridderbusch.kd@sni-usa.com (America (North & South))
%%COMMENTS
%%    I modified the original format to produce headlines, which show
%%    the current section. I did that with only a limited knowledge of
%%    TeX. So, if anyone can suggest ways, to do it better, just let
%%    me know. At the moment I'm about 95% happy with the overall
%%    format. Perhaps someone can show me a better layout. When you 
%%    want to use the 3 column format you should have a dvi-driver,
%%    which is able to rotate the page by 90 degrees or a printer
%%    which is able to do the same thing. I am printing on an HP2000 
%%    laser printer, which does the rotating for me. The \vsize and 
%%    \hsize values are currently setup to give a best fit on european
%%    A4 paper.
%%
%%    This set of macros now uses the expanded plain package from Karl
%%    Berry for the table of contents. Unfortunately the table must be
%%    corrected by hand, since I'm using the columnnumber instead of
%%    the pagenumber. I was unable to modify to code from expanded
%%    plain to produce to correct results with the columnnumbers.
%%    (This really needs a TeX wizards with all this delayed expansion
%%    of macros.) Addtionally the table of contents must be sorted.
%%
%%    The \function macro and all other macros, on which this macro
%%    depends are from a LaTeX MANPAGE DOCUMENT style file by Rong Chen
%%    (rchen@c.uiuc.edu). I did the modifications to get it run under
%%    plain TeX. The needed for-loop macros are directly from the
%%    LaTeX.tex by Leslie Lamport.

\let\nobibtex=t
\ifx\eplain\undefined \input eplain \fi

\def\tocsectionentry#1#2#3{\line{\bf #1 \dotfill\ #2}}%

% make \bye not \outer so that the \def\bye in the \else clause below
% can be scanned without complaint.
\def\bye{\par\vfill\supereject\end}

\newdimen\intercolumnskip
\newbox\columna
\newbox\columnb

\newbox\rightcolhead
\newbox\medcolhead
\newbox\leftcolhead

\newif\ifusefirstmark
\usefirstmarktrue

\newcount\columnno\columnno=1

\def\ncolumns{\the\columnsperpage}

\message{[\ncolumns\space
  column\if 1\ncolumns\else s\fi\space per page]}

\def\scaledmag#1{ scaled \magstep #1}

% This multi-way format was designed by Stephen Gildea
% October 1986.
\if 1\ncolumns
  \hsize 4in
  \vsize 10in
  \voffset -.7in
  \font\titlefont=\fontname\tenbf \scaledmag3
  \font\titlett=\fontname\tentt \scaledmag3
  \font\headingfont=\fontname\tenbf \scaledmag2
  \font\smallfont=\fontname\sevenrm
  \font\smallsy=\fontname\sevensy

  \footline{\hss\folio}
  \def\makefootline{\baselineskip10pt\hsize6.5in\line{\the\footline}}
\else
  \if 2\ncolumns
    \hoffset -.57in %-.29in
    %\voffset -.745in
    \hsize 3.2in
    \vsize 7.95in
  \else
    \hoffset -.47in
    \voffset -.85in
    \hsize 3.2in
    \vsize 7.55in
  \fi
  \font\titlefont=cmbx10 \scaledmag2
  \font\titlett=cmtt10 \scaledmag2
  \font\headingfont=cmbx10 \scaledmag1
  \font\smallfont=cmr6
  \font\smallsy=cmsy6
  \font\eightrm=cmr8
  \font\eightbf=cmbx8
  \font\eightsl=cmsl8
  \font\eightit=cmti8
  \font\eighttt=cmtt8
  \font\eightsy=cmsy8
  \textfont0=\eightrm
  \textfont2=\eightsy
  \def\rm{\eightrm}
  \def\sl{\eightsl}
  \def\bf{\eightbf}
  \def\it{\eightit}
  \def\tt{\eighttt}
  \normalbaselineskip=.8\normalbaselineskip
  \normallineskip=.8\normallineskip
  \normallineskiplimit=.8\normallineskiplimit
  \normalbaselines\rm           %make definitions take effect

  % decrease height of strut
  \setbox\strutbox=\hbox{\vrule height6.5pt depth2.5pt width0pt}

  \if 2\ncolumns
    \let\maxcolumn=b
    \headline{\rm\kern.5\intercolumnskip%
	      \box\leftcolhead\hss\box\rightcolhead%
	      \kern.5\intercolumnskip}
    \footline{\hss\rm\folio\hss}
    \def\makefootline{}%\vskip 2in \hsize=6.86in\line{\the\footline}}
    %\def\makeheadline{\hsize=6.86in\line{\the\headline}}
    \def\makeheadline{\hsize=2\hsize%
		      \advance\hsize by 2\intercolumnskip%
		      \line{\the\headline}}
    \nopagenumbers
  \else \if 3\ncolumns
    \let\maxcolumn=c
    \headline{\rm\kern.5\intercolumnskip%
	      \box\leftcolhead\hss\box\medcolhead\hss\box\rightcolhead%
	      \kern.5\intercolumnskip}
    \footline{\hss\rm\folio\hss}
    \def\makefootline{}%\vskip .3in \hsize=10.52in\line{\the\footline}}
    %\def\makeheadline{\hsize=10.52in\line{\the\headline}}
    \def\makeheadline{\hsize=3\hsize%
		      \advance\hsize by 3\intercolumnskip%
		      \line{\the\headline}}
    \nopagenumbers
  \else
    \errhelp{You must set \columnsperpage equal to 1, 2, or 3.}
    \errmessage{Illegal number of columns per page}
  \fi\fi

  \intercolumnskip=.46in
  \def\abc{a}
  \output={%
      % This next line is useful when designing the layout.
      % \immediate\write16{Column \folio\abc\space starts with \firstmark}
      \if \maxcolumn\abc
	\global\setbox\rightcolhead\vbox{
	  \hbox to \hsize{\strut\the\columnno\hss\ifusefirstmark\firstmark%
	    \global\usefirstmarkfalse\else\topmark\fi\hss\the\columnno}
	  \vskip 2pt \hrule\vskip 3pt}
	\multicolumnformat \global\def\abc{a}
	\global\advance\columnno by 1
      \else\if a\abc
        \global\setbox\columna\columnbox \global\def\abc{b}
	\global\setbox\leftcolhead\vbox{
	  \hbox to \hsize{\strut\the\columnno\hss\ifusefirstmark\firstmark
	      \global\usefirstmarkfalse\else\topmark\fi\hss\the\columnno}
            \vskip 2pt \hrule\vskip 3pt}
        %% in case we never use \columnb (two-column mode)
        \global\setbox\columnb\hbox to -\intercolumnskip{}
	\global\advance\columnno by 1
      \else
        \global\setbox\columnb\columnbox \global\def\abc{c}
	\global\setbox\medcolhead\vbox{
	  \hbox to \hsize{\strut\the\columnno\hss\ifusefirstmark\firstmark%
	    \global\usefirstmarkfalse\else\topmark\fi\hss\the\columnno}
	  \vskip 2pt \hrule\vskip 3pt}
	\global\advance\columnno by 1
        \fi\fi}
  \def\multicolumnformat{\shipout\hbox{\vrule
      \vbox{\hrule\vskip10pt\makeheadline
        \hbox{\kern.5\intercolumnskip
              \box\columna
              \kern.5\intercolumnskip\vrule\kern.5\intercolumnskip
              \box\columnb
              \kern.5\intercolumnskip\vrule\kern.5\intercolumnskip
              \pagebody
              \kern.5\intercolumnskip}
        \makefootline\vskip10pt\hrule}\vrule}\advancepageno}
  \def\columnbox{\leftline{\pagebody}}

  \def\bye{\par\vfill\supereject
    \if a\abc \else\null\vfill\eject\fi
    \if a\abc \else\null\vfill\eject\fi
    \end}
\fi

% we won't be using math mode much, so redefine some of the characters
% we might want to talk about
\catcode`\^=12
\catcode`\_=12
\catcode`\|=12
\def\underscore{{\tt\char"5F}}
\def\asterix{{\tt\char"2A}}
\def\pipe{{\tt\char"7C}}
\let\_=\underscore
\let\*=\asterix
\let\|=\pipe

\chardef\\=`\\
\chardef\{=`\{
\chardef\}=`\}

\parindent 0pt
\parskip 1ex plus .5ex minus .5ex

\def\small{\smallfont\textfont2=\smallsy\baselineskip=.8\baselineskip}

\outer\def\newcolumn{\vfill\eject}

\outer\def\title#1{{\let\tt=\titlett%
   \titlefont\centerline{#1}}\vskip 1ex plus .5ex}

\outer\def\section#1{\mark{#1}\par\goodbreak%\filbreak
  \vskip 3ex plus 2ex minus 2ex {\headingfont #1}%\mark{#1}%
  \vskip 2ex plus 1ex minus 1.5ex%
  \message{[#1]}%
  \writenumberedtocentry{section}{#1}{\the\columnno}}

\def\<#1>{$<${\rm #1}$>$}

\newbox\startcobox
\newbox\comment
\newbox\strucbox
\setbox\startcobox\hbox{/{\tt *}\ }
\newdimen\startcowidth
\startcowidth=\wd\startcobox

\newdimen\parasize
\newdimen\strucindent

\def\defaultstrucindent{\strucindent=0.44\hsize}
\defaultstrucindent

\long\def\para#1{\parasize=\hsize\advance\parasize by -\strucindent
  \advance\parasize by -4pt\relax
  \setbox\comment\hbox{#1}\ifdim\wd\comment = 0pt\relax
  \else%\hbox to 0pt{\hskip -\startcowidth\unhcopy\startcobox}}
  \everypar={\llap{\unhcopy\startcobox}}
  \vtop{\hsize=\parasize\leftskip=\startcowidth
    \tolerance=10000\raggedright
  \noindent\unhbox\comment\ {\tt *}/}
  \fi}

\def\beginstructure#1{\vskip\parskip\begingroup
  \parskip=0pt\parindent=0pt
  \noindent{\sl #1 $\{$}\par
  \advance\leftskip by \strucindent}

\def\endstructure#1{$\}$ #1;\endgroup}

%structure element
\def\struc#1 #2;#3{\begingroup%
  \setbox\strucbox\hbox{\quad\sl #1\enskip{\bf #2};}%
  \setbox0=\hbox{#3}
  \noindent%
  \ifdim\wd\strucbox>\strucindent
  \hbox{\hskip -\strucindent\box\strucbox\hss}\par
  \ifdim\wd0 > 0pt\relax\leavevmode\para{\unhbox0}\fi%
  \else
  \hbox to 0pt{\hskip -\strucindent\box\strucbox\hss}\para{\unhbox0}\fi%
  \par\endgroup}

\def\routines{\setbox0=\hbox{Routines concerned:\ }\hangindent=\wd0
  \hangafter=1\leavevmode\box0}

\def\twocol#1#2{\hskip\keyindent\relax#1&#2\cr}

% two column table element with vrule

\def\twocolrule#1#2{#1&&#2\cr}

%

\def\threecol#1#2#3{\hskip\keyindent\relax#1&#2&#3\cr}

% three column table element with vrule

\def\threecolrule#1#2#3{&#1&&#2&&#3&\cr}

\def\paralign{\vskip\parskip\halign}

\def\begindefines{\medskip%\vskip\parskip
  \vbox\bgroup\offinterlineskip\hrule
  \halign to \hsize\bgroup\strut
     \vrule##&
     \enskip##\hfil\enskip
     \tabskip=1em plus2em minus.5em
     &\vrule##&
     \enskip\hfil##\hfil\enskip
     &\vrule##&
     \enskip##\hfil\enskip
     &\tabskip=0pt\vrule##\cr}

\def\enddefines{\egroup\hrule\egroup}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% definitions for the library reference card
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%function (not used anymore)
\def\func#1 #2(#3);{\leavevmode\hbox to \hsize{%
  {\sl #1}\enskip{\bf #2} (\enskip{\sl #3}\enskip);\null\hfill}}

%function with a large definition (not used anymore)
\def\lfunc#1 #2(#3,#4);{\paralign{##\enskip &##\hfil\cr
  {\sl #1}\enskip\relax{\bf #2} (&{\sl #3},\cr
  \hfil & {\sl #4}\enskip);\cr\noalign{\vskip -\parskip}}}

\def\expl#1{\leavevmode\baselineskip=.80\baselineskip\tolerance=2000
  \hbox to \hsize{\hskip\myindent\vtop
  {\advance\hsize by -\myindent\relax#1}\hfil}\goodbreak}

\newdimen\keyindent

\newdimen\myindent
\myindent=.10\hsize

\def\beginindentedkeys{\keyindent=\myindent}
\def\endindentedkeys{\keyindent=0em}
\endindentedkeys

\def\begintwocolumn{\hskip\keyindent\relax
  \vbox\bgroup\offinterlineskip
  \halign\bgroup\strut\quad\hfil##\quad&\vrule##&\quad##\hfil\quad\cr}

\def\endtwocolumn{\noalign{\smallskip}\egroup\egroup}

\def\beginthreecolumn{\hskip\keyindent\relax
  \vbox\bgroup\offinterlineskip
    \def\threecolrule##1##2##3{##1&&##2&&##3\cr}
    \halign\bgroup\strut\quad##\hfil\quad&\vrule##&
                  \quad##\hfil\quad&\vrule##&\quad##\hfil\cr}

\let\endthreecolumn=\endtwocolumn

\catcode`@ = \letter

\def\@nnil{\@nil}
\def\@fornoop#1\@@#2#3{}

\def\@for#1:=#2\do#3{\edef\@fortmp{#2}\ifx\@fortmp\empty \else
    \expandafter\@forloop#2,\@nil,\@nil\@@#1{#3}\fi}

\def\@forloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else
       #5\def#4{#2}\ifx #4\@nnil \else#5\@iforloop #3\@@#4{#5}\fi\fi}

\def\@iforloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
       \let\@nextwhile=\@fornoop \else
      #4\relax\let\@nextwhile=\@iforloop\fi\@nextwhile#2\@@#3{#4}}

\newdimen\argindent \argindent -1pt % indentation for function arguments

\def\function{\leavevmode\@func@star}
\def\@func@star#1{\expandafter\@function#1 \par\vskip-\parskip}
\def\@func@norm#1{\expandafter\@function#1 \medskip\par\vskip-\parskip}

\newdimen\arg@dim         % temp variables that you don't want to know
\newdimen\arg@indent
\newdimen\line@siz
\newbox\arg@box

\def\@function#1(#2)#3 {
  \expandafter\print@name#1 \@@
  \setbox\arg@box=\hbox{\rm\ $($\ }%
  \global\advance\arg@dim\wd\arg@box
  \unskip\box\arg@box
  \edef\@fortmp{#2}%
  \ifx\@fortmp\empty {\rm $)$#3}\else
    \setbox\arg@box=\hbox{\rm\ $)$;}%
    \global\line@siz\hsize \global\advance\line@siz-\wd\arg@box
    \ifdim\argindent<0pt
      \global\arg@indent\arg@dim \else\global\arg@indent\argindent\fi
    \def\@comma{}%
    \@for\@tempa:=#2\do{%   
      \setbox\arg@box=\hbox{\@comma}%
      \global\advance\arg@dim\wd\arg@box
      \unskip\@comma\def\@comma{\nobreak,\penalty-\@m\ }%
      \expandafter\print@arg\@tempa\@@
    }%
    \unskip\nobreak\hbox{\rm\ $)$#3}%
  \fi
}

\def\print@name#1#2 #3\@@{%
  \edef\tmp@name{#3}%
  \ifx\tmp@name\empty
    \setbox\arg@box=\hbox{\bf #1#2}%
    \else\setbox\arg@box=\hbox{\sl #1#2 \bf #3\unskip}\fi
  \global\arg@dim=0pt \global\advance\arg@dim\wd\arg@box
  \unskip\box\arg@box
}

\def\print@arg#1\@@{\expandafter\print@type#1 \@@}

\def\print@type#1#2 #3\@@{%
  \setbox\arg@box=\hbox{{\sl #1#2}%
    \ifx #3\@nil\else\expandafter\print@dummy#3=\@@\fi
    \unskip\/}%
  \global\advance\arg@dim\wd\arg@box
  \ifdim\arg@dim>\line@siz
    \global\arg@dim\arg@indent \global\advance\arg@dim\wd\arg@box
    \hfill\penalty-\@m\hbox{}\kern\arg@indent\fi
  \box\arg@box
}

\def\print@dummy#1=#2\@@{%
  \edef\tmp@name{#1}\def\a@space{ }%
  \ifx\tmp@name\a@space\else
    {\unskip\sl\ #1\/}%
    \ifx #2\@nil\else{\unskip\sl\ $=$\ }\strip@eq#2\fi
  \fi
}

\def\strip@eq#1={\rm \expandafter\ignorespaces#1\unskip}

\catcode`@ = \other